import "./assets/main.css";

import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";

let app = createApp(App);
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  app.use(router).mount("#app");
} else {
  renderWithQiankun({
    mount(props) {
      app = app ?? createApp(App);
      app
        .use(router)
        .mount(
          props.container
            ? props.container.querySelector("#app")
            : document.getElementById("app")
        );
      // 监听主应用注入的全局状态
      props.onGlobalStateChange((state, prev) => {
        // state: 变更后的状态; prev 变更前的状态
      });
    },
    bootstrap() {},
    update() {},
    unmount() {
      app?.unmount();
      app = null;
    },
  });
}
